package com.axsoft.jobimp;

import com.axsoft.jobimp.types.BLK;
import com.axsoft.jobimp.types.UTF8;
import com.axsoft.jobimp.types.sTLD;
import com.axsoft.jobimp.types.wTLD;


/**
 * 
 * @author RankoR
 *
 * This factory constructs various BEX packets
 * See the BEX structure in BEX.java
 *
 */
public class BexFactory {
	
	/**
	 * OBIMP_BEX_COM_CLI_HELLO (See 1.1 in Dumps.docx)
	 */
	public static final BLK create_OBIMP_BEX_COM_CLI_HELLO(final String pAccountName) {
		final UTF8 accountName = new UTF8(pAccountName);
		final wTLD wTld = new wTLD(Constants.WTLD_UTF8_ACCOUNT_NAME, accountName.getData());
		final OHeader header = new OHeader(0x00, Constants.OBIMP_BEX_COM, Constants.OBIMP_BEX_COM_CLI_HELLO, 0x0000, wTld.getLength());
		return createBex(header, wTld);
	}
	
	/**
	 * Create BEX from the given OHeader & sTLD
	 */
	public static final BLK createBex(final OHeader pHeader, final sTLD pTld) {
		return createBLK(pHeader.toBLK(), pTld.toBLK());
	}
	
	
	/**
	 * Create BEX from the given OHeader & wTLD
	 */
	public static final BLK createBex(final OHeader pHeader, final wTLD pTld) {
		return createBLK(pHeader.toBLK(), pTld.toBLK());
	}
	
	/**
	 * Create BLK from other given BLKs 
	 */
	private static final BLK createBLK(final BLK ... pBlk) {
		final BLK retBlk = new BLK();
		
		for (BLK blk : pBlk) {
			retBlk.addBLK(blk);
		}
		
		return retBlk;
	}
	
}
